home comics writing pictures archive about

FormatHelper.cpp

Language: C++
Last Modified: 2022-09-10 5:29:28 PM UTC
File Size: 1363 bytes
http://www.penguinstew.ca/example/CodeFormater/FormatHelper.cpp
#include "FormatHelper.h"
#include "PhpHelper.h"
#include "Type.h"
#include <string>
#include <regex>
std::string FormatHelper::GetWord(std::string line, int pos, std::regex regEx)
{
for (unsigned int j = pos; j < line.length(); j++)
{
if (!std::regex_match(line.substr(j, 1), regEx))
{
return line.substr(pos, j - pos);
}
}
return "";
}
bool FormatHelper::IsMatch(std::string line, std::string str, int lineStartPos, std::regex nextCharRegEx)
{
int strLength = str.length();
int lineLength = line.length();
if (lineLength - lineStartPos < strLength)
{
return false;
}
if (line.compare(lineStartPos, strLength, str) != 0)
{
return false;
}
if (lineLength - lineStartPos == strLength)
{
return true;
}
if (!std::regex_match(line.substr(lineStartPos + strLength, 1), nextCharRegEx))
{
return true;
}
return false;
}
int FormatHelper::EscapeCount(std::string line, std::string escape, int lineStartPos)
{
int escapeLength = escape.length();
int escapeCount = 0;
if (escapeLength == 0)
{
return escapeCount;
}
//Loop back from start
for (unsigned int i = lineStartPos - escapeLength; i >= 0; i -= escapeLength) {
if (line.compare(i, escapeLength, escape) == 0)
{
escapeCount++;
}
else {
break;
}
}
return escapeCount;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71